/**
 * 
 */
package model.admin;

import java.sql.ResultSet;
import java.util.ArrayList;

import myutil.Connect;

import vo.StaffFinancialsVo;
import vo.mixed.CollegeStaffFinancialsVo;

/**
 * @author Sony
 * 
 */
public class StaffFinancialsMo {
	ArrayList<CollegeStaffFinancialsVo> list = new ArrayList<CollegeStaffFinancialsVo>();

	public ArrayList<CollegeStaffFinancialsVo> getFinancialHistory(int staff_id) {
		Connect c = new Connect();
		String query = "select csf.college_staff_financial_id,cs.staff_id,transaction_id,csf.acc_no,roll_number,staff_name,salary_amount,salary_date,payment_made,year,month from college_staff cs, college_staff_financial csf where cs.staff_id=csf.staff_id and cs.staff_id="
				+ staff_id;
		System.out.println(query);
		try {
			ResultSet rs = c.getResult(query);
			while (rs.next()) {
				CollegeStaffFinancialsVo vo = new CollegeStaffFinancialsVo();
				vo.setStaff_id(rs.getInt("staff_id"));
				vo.setRoll_number(rs.getString("roll_number"));
				vo.setStaff_name(rs.getString("staff_name"));
				vo.setSalary_amount(rs.getInt("salary_amount"));
				vo.setSalary_date(rs.getString("salary_date"));
				vo.setPayment_made(rs.getInt("payment_made"));
				vo.setYear(rs.getInt("year"));
				vo.setMonth(rs.getInt("month"));
				vo.setTransaction_id(rs.getString("transaction_id"));
				vo.setAcc_no(rs.getInt("acc_no"));
				vo.setCollege_staff_financial_id(rs
						.getInt("college_staff_financial_id"));
				list.add(vo);
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	public void addEntry(StaffFinancialsVo vo) {
		Connect c = new Connect();
		String query = "insert into college_staff_financial(staff_id,salary_amount,salary_date,payment_made,year,month,acc_no,transaction_id) values("
				+ vo.getStaff_id()
				+ ","
				+ vo.getSalary_amount()
				+ ",CURDATE(),"
				+ vo.getPayment_made()
				+ ","
				+ vo.getYear()
				+ ","
				+ vo.getMonth()
				+ ","
				+ vo.getAcc_no()
				+ ",'"
				+ vo.getTransaction_id() + "')";
		System.out.println(query);
		try {
			c.dml(query);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void editEntry(StaffFinancialsVo vo) {
		Connect c = new Connect();
		String query = "update college_staff_financial set staff_id="
				+ vo.getStaff_id() + ",salary_amount=" + vo.getSalary_amount()
				+ ",payment_made=" + vo.getPayment_made() + ",year="
				+ vo.getYear() + ",month=" + vo.getMonth() + ",acc_no="
				+ vo.getAcc_no() + ",transaction_id='" + vo.getTransaction_id() + "' where college_staff_financial_id="+vo.getCollege_staff_financial_id();

		System.out.println(query);
		try {
			c.dml(query);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public ArrayList<CollegeStaffFinancialsVo> getEntryDetails(int college_staff_financial_id) {
		Connect c=new Connect();
		String query="select csf.college_staff_financial_id,cs.staff_id,transaction_id,csf.acc_no,roll_number,staff_name,salary_amount,salary_date,payment_made,year,month from college_staff cs, college_staff_financial csf where cs.staff_id=csf.staff_id and csf.college_staff_financial_id="
				+ college_staff_financial_id;
		System.out.println(query);
		
		try {
			ResultSet rs = c.getResult(query);
			while (rs.next()) {
				CollegeStaffFinancialsVo vo = new CollegeStaffFinancialsVo();
				vo.setStaff_id(rs.getInt("staff_id"));
				vo.setRoll_number(rs.getString("roll_number"));
				vo.setStaff_name(rs.getString("staff_name"));
				vo.setSalary_amount(rs.getInt("salary_amount"));
				vo.setSalary_date(rs.getString("salary_date"));
				vo.setPayment_made(rs.getInt("payment_made"));
				vo.setYear(rs.getInt("year"));
				vo.setMonth(rs.getInt("month"));
				vo.setTransaction_id(rs.getString("transaction_id"));
				vo.setAcc_no(rs.getInt("acc_no"));
				vo.setCollege_staff_financial_id(rs.getInt("college_staff_financial_id"));
				list.add(vo);
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	public void deleteEntry(int college_staff_financial_id) {
		
		
	}
}
